package GUI;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;

import core.model.Sugerencia;
import core.model.Usuario;
import core.thread.Mail;

public class panelAdministradorResponderSugerencia extends javax.swing.JPanel
		implements ActionListener {
	/**
	 * variables estaticas
	 */
	private static final long serialVersionUID = 5238955873455219528L;
	private static final int PLAIN_MESSAGE = 0;
	private static final int OK_CANCEL_OPTION = 0;
	private VentanaManager ventanaManager=VentanaFactory.getInstance();
	
	Sugerencia sug=ventanaManager.getSugerencia(panelAdministradorSugerenciasOtras.codigo_sugerenciaOtra);
	/**
	 * contructor del panel
	 */
	public panelAdministradorResponderSugerencia() {
		initComponents();
	}

	private void initComponents() {

		eUnidad = new javax.swing.JLabel();
		bTitulo = new javax.swing.JButton();
		bAgregar = new javax.swing.JButton();
		bSalir = new javax.swing.JButton();
		bCancelar = new javax.swing.JButton();
		tfDestinatario = new javax.swing.JTextField();
		eUnidad1 = new javax.swing.JLabel();
		tfAsunto = new javax.swing.JTextField();
		eMensaje = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		tadescripcion = new javax.swing.JTextArea();

		setBackground(new java.awt.Color(255, 255, 255));
		
		

		
		eUnidad.setBackground(new java.awt.Color(255, 255, 255));
		eUnidad.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eUnidad.setForeground(new java.awt.Color(102, 102, 102));
		eUnidad.setText("PARA:");

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png")); // NOI18N
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));
		bTitulo.addActionListener(this);

		bAgregar.setBackground(new java.awt.Color(255, 255, 255));
		bAgregar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bAgregar.setForeground(new java.awt.Color(243, 15, 120));
		bAgregar.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonEnviar.png")); // NOI18N
		bAgregar.setBorder(null);
		bAgregar.addActionListener(this);

		bSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		bSalir.setBorderPainted(false);
		bSalir.setBackground(new java.awt.Color(255, 255, 255));
		bSalir.addActionListener(this);

		bCancelar.setBackground(new java.awt.Color(255, 255, 255));
		bCancelar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bCancelar.setForeground(new java.awt.Color(243, 15, 120));
		bCancelar
				.setIcon(new javax.swing.ImageIcon(
						"src/GUI/resources/botonCancelar.png")); // NOI18N
		bCancelar.setBorder(null);
		bCancelar.setBorderPainted(false);
		bCancelar.addActionListener(this);
		
		

		tfDestinatario.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfDestinatario.setToolTipText("");
		tfDestinatario.setText(sug.getNick());
		tfDestinatario.setEnabled(false);

		eUnidad1.setBackground(new java.awt.Color(255, 255, 255));
		eUnidad1.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eUnidad1.setForeground(new java.awt.Color(102, 102, 102));
		eUnidad1.setText("ASUNTO:");

		tfAsunto.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tfAsunto.setToolTipText("");
		tfAsunto.setText(sug.getAsunto());
		tfAsunto.setEnabled(false);

		eMensaje.setBackground(new java.awt.Color(255, 255, 255));
		eMensaje.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eMensaje.setForeground(new java.awt.Color(102, 102, 102));
		eMensaje.setText("MENSAJE:");

		tadescripcion.setColumns(20);
		tadescripcion.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		tadescripcion.setRows(5);
		tadescripcion.setText("Su solicitud con asunto: "+sug.getAsunto()+" ha sido recibida. En breves nuestro departamento de atencion al cliente se pondra en contacto con usted \n\n Un saludo \n\n Departamento tecnico");
		tadescripcion.setEnabled(false);
		jScrollPane1.setViewportView(tadescripcion);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(77, 77, 77)
						.add(eUnidad,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								49,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.UNRELATED)
						.add(tfDestinatario,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								279, Short.MAX_VALUE).add(255, 255, 255))
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(133, 133, 133)
										.add(jScrollPane1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												369,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.add(layout.createSequentialGroup()
										.add(192, 192, 192).add(bAgregar)
										.add(56, 56, 56).add(bCancelar)))
						.addContainerGap(200, Short.MAX_VALUE))
				.add(layout
						.createSequentialGroup()
						.add(51, 51, 51)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(eMensaje,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												81,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE))
								.add(layout
										.createSequentialGroup()
										.add(6, 6, 6)
										.add(eUnidad1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												72,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.UNRELATED)
										.add(tfAsunto,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												279, Short.MAX_VALUE)
										.add(252, 252, 252))))
				.add(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(layout
								.createSequentialGroup()
								.addContainerGap()
								.add(bTitulo)
								.addPreferredGap(
										org.jdesktop.layout.LayoutStyle.RELATED,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE).add(bSalir)
								.addContainerGap())));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(166, 166, 166)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.BASELINE)
								.add(eUnidad)
								.add(tfDestinatario,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.BASELINE)
								.add(eUnidad1)
								.add(tfAsunto,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.add(18, 18, 18)
						.add(eMensaje)
						.add(18, 18, 18)
						.add(jScrollPane1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								61,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.add(18, 18, 18)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.BASELINE)
								.add(bAgregar,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										44,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(bCancelar,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										44,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
						.addContainerGap(45, Short.MAX_VALUE))
				.add(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(layout
								.createSequentialGroup()
								.addContainerGap()
								.add(layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(bTitulo).add(bSalir))
								.addContainerGap(317, Short.MAX_VALUE))));
	}

	private javax.swing.JButton bAgregar;
	private javax.swing.JButton bCancelar;
	private javax.swing.JButton bSalir;
	private javax.swing.JButton bTitulo;
	private javax.swing.JLabel eMensaje;
	private javax.swing.JLabel eUnidad;
	private javax.swing.JLabel eUnidad1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextArea tadescripcion;
	private javax.swing.JTextField tfDestinatario;
	private javax.swing.JTextField tfAsunto;
	private JFrame actual;
	private JPanel estePanel = this;

	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource() == bTitulo) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAdministradorPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bCancelar) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAdministradorPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(26));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAgregar) {
			System.out.println(sug.getNick());
			Usuario user=ventanaManager.findUsuarioBy(sug.getNick());
			Mail email= new Mail(user.getEmail(),"Recibida la sugerencia con asunto "+sug.getAsunto(),tadescripcion.getText());
			email.run();
			
			
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAdministradorPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

			

		}

	}
}
